<template>
	<view class="page-body">
		<!-- #ifdef APP-PLUS -->
		<view class="status_bar">
			<view class="top_view"></view>
		</view>
		<!-- #endif -->
		<!-- 头部导航 -->
		<view class="header">
			<view class="left_box" @click="goBack()">
				<image class="left_icon" mode="widthFix" src="@/static/images/leftMark_icon.png"></image>
			</view>
			<view class="title">线索跟进</view>
			<view class="right_box" v-if="isEdit" @click="subForm('cancelled')">取消跟进</view>
			<view class="right_box" v-else></view>
		</view>

		<!-- 内容 -->
		<view class="content_box">
			<view class="followUp_title objectiveTitle">跟进目的</view>
			<view class="followUpForm_box">			
				<view class="objective_ul">
					<block v-for="(item,idx) in objective_radio_Arr" :key="idx">
						<view :class="['objective_li', item.isChecked ? 'li_checked':'']" @click="objectiveRadioClick(idx, item)">
							<image class="iconImg" :src="require(item.isChecked ? '@/static/images/radio_icon.png' : '@/static/images/radio_no_icon.png')"></image>{{item.objectiveName}}
						</view>
					</block>
				</view>			
				<view class="objective_checkbox_box">
					<block v-for="(item,idx) in objective_checkbox_Arr" :key="idx">
						<view :class="['objective_li', item.isChecked ? 'li_checked':'']" @click="objectiveCheckboxClick(idx, item)">
							<image class="iconImg" :src="require(item.isChecked ? '@/static/images/checkbox_icon.png' : '@/static/images/checkbox_no_icon.png')"></image>{{item.objectiveName}}
						</view>
					</block>
				</view>
			</view>
			
			<view class="followUp_title">跟进形式</view>
			<view class="followUpForm_box">	
				<view class="followUpForm_ul">
					<block v-for="(item,idx) in followUpFormArr" :key="idx">
						<view :class="['followUpForm_li', item.isChecked ? 'followUpFormLi_checked':'']" @click="followUpClick(idx)">
							<image class="formImg" v-if="idx == 0" :src="require(item.isChecked ? '@/static/images/telnew_img.png' : '@/static/images/telnew_no_img.png')"></image>
							<image class="formImg" v-else-if="idx == 1" :src="require(item.isChecked ? '@/static/images/informationnew_img.png' : '@/static/images/informationnew_no_img.png')"></image>
							<image class="formImg" v-else-if="idx == 2" :src="require(item.isChecked ? '@/static/images/interviewnew_img.png' : '@/static/images/interviewnew_no_img.png')"></image>
							<image class="formImg" v-else-if="idx == 3" :src="require(item.isChecked ? '@/static/images/meetnew_img.png' : '@/static/images/meetnew_no_img.png')"></image>
							<view class="formName" :style="{color: item.isChecked ?'#3B86FC':'#43425D'}">{{item.fallowUpName}}</view>						
						</view>
					</block>
				</view>
			</view>
			

			<view class="followUp_title">跟进信息</view>
			<view class="fillIn_info">
				<view class="infoUl">
					<!-- <block v-if="isEdit">
						<view class="infoLi">
							<view class="infoLable required">开始时间</view>
							<view class="infoVal required">
								<picker mode="date" :value="formObj.startTime" @change="bindDateChange($event, 0)">
									<view class="uni-input">{{ formObj.startTime || '请选择' }}
										<uni-icons class="rightIcon" color="#3B86FF" size="18" type="forward" />
									</view>
								</picker>
							</view>
						</view>
						<view class="infoLi">
							<view class="infoLable required">结束时间</view>
							<view class="infoVal required">
								<picker mode="date" :value="formObj.endTime" @change="bindDateChange($event, 1)">
									<view class="uni-input">{{ formObj.endTime || '请选择' }}
										<uni-icons class="rightIcon" color="#3B86FF" size="18" type="forward" />
									</view>
								</picker>
							</view>
						</view>
					</block> -->
					<view class="infoLi">
						<view class="infoLable required">跟进时间</view>
						<view class="infoVal required">
							<picker mode="date" :value="formObj.followTime" @change="bindDateChange($event, 2)">
								<view class="uni-input" style="background: none;">{{ formObj.followTime || '请选择' }}
									<uni-icons class="rightIcon" color="#A5A4BF" size="18" type="forward" />
								</view>
							</picker>
						</view>
					</view>
					<view class="infoLi" style="flex-direction: column;margin-top: 16rpx;">
						<view class="infoLable required" style="width: 100%;">意向级别</view>
						<!-- <view class="infoVal required" @click="levelClick">{{ formObj.intentionLevel || '请选择' }}
							<uni-icons class="rightIcon" color="#A5A4BF" size="18" type="forward" />
						</view> -->
						<view class="infoLiLeve">
							<view  :class="['infoLiLeveItem', isInfoLiLeveItem==leveidx ? 'infoLiLeveItem_checked':'']" v-for="(leveitem,leveidx) in levelArr" :key='leveidx' @click="leveitemCheFun(leveitem,leveidx)">
								{{leveitem}}
							</view>
						</view>		

					</view>
					
	
					
					<view class="infoLi" v-if="exhibition=='1' || exhibition=='2' || exhibition=='4'">
						<view class="infoLable required">{{ exhibition=='4' ? '退单原因' : '战败原因'}}</view>
						<view class="infoVal required" @click="showTree">
							 {{ joinStr(formObj.invalidReasonsStr) || '请选择'}} <uni-icons class="rightIcon" color="#A5A4BF" size="18" type="forward" />
						</view>
					</view>
					<block v-if="exhibition=='3' || exhibition=='5'">
						<view class="infoLi">
							<view class="infoLable required">意向车型</view>
							<view class="infoVal required" @click="getIntentionCar">
								{{ formObj.intentCarStyle ? formObj.intentCarModel+'/'+formObj.intentCarStyle : '请选择' }}
								<uni-icons class="rightIcon" color="#A5A4BF" size="18" type="forward" />
							</view>
						</view>
						<view class="infoLi">
							<view :class="['infoLable', exhibition == '5' && isChannel('0') ? 'required':'']">活动名称</view>
							<view :class="['infoVal', exhibition == '5' && isChannel('0') ? 'required':'']">
								<picker @change="activityChange" :value="actIndex" range-key="activityName" :range="activityArr">
									{{formObj.activityName || '请选择'}}
									<uni-icons class="rightIcon" color="#A5A4BF" size="18" type="forward" />
								</picker>
							</view>
						</view>
						<view class="infoLi">
							<view :class="['infoLable', isChannel('1') ? 'required':'']">来源渠道</view>
							<view :class="['infoVal', isChannel('1') ? 'required':'']">
								<channel-picker ref="channelPicker" :defaultRegion="[formObj.firstChannelId || 0, formObj.secondChannelId || 0]" :isSelectAll="false"  @getRegion="handleGetRegion">
									{{formObj.channelName ? formObj.channelName : '请选择'}}
									<uni-icons class="rightIcon" color="#A5A4BF" size="18" type="forward" />
								</channel-picker>
							</view>
						</view>
						<view class="infoLi">
							<view :class="['infoLable', isChannel('2') ? 'required':'']">客户承诺到店</view>
							<view :class="['infoVal', isChannel('2') ? 'required':'']">		
								 <view class="myModalBox_concat_radio">
								   <view
									 :class="
									   isRadioVal
										 ? 'myModalBox_concat_radioitem atv'
										 : 'myModalBox_concat_radioitem'
									 "
									 @click="isCheckedFun"
								   >
									 <i :class="isRadioVal ? 'radiosty atv' : 'radiosty'"></i>							
									 <label for="cheyes1"> 是</label>
								   </view>
								   <view
									 :class="
									   isRadioVal
										 ? 'myModalBox_concat_radioitem'
										 : 'myModalBox_concat_radioitem atv'
									 "
									 @click="isCheckedFun"
								   >
									 <i :class="isRadioVal ? 'radiosty' : 'radiosty atv'"></i>							     
									 <label for="cheyes2">否</label>
								   </view>
								 </view>
							</view>
						</view>
						<view class="infoLi">
							<view class="infoLable">预计成交时间</view>
							<view class="infoVal">
								<picker mode="date" :value="formObj.estTranTime" @change="bindDateChange($event, 3)">
									<view class="uni-input">{{ formObj.estTranTime || '请选择' }}
										<uni-icons class="rightIcon" color="#A5A4BF" size="18" type="forward" />
									</view>
								</picker>
							</view>
						</view>
						<!-- <view class="infoLi">
							<view class="infoLable">配置</view>
							<view class="infoVal">请选择
								<uni-icons class="rightIcon" color="#3B86FF" size="18" type="forward" />
							</view>
						</view>
						<view class="infoLi_two">
							<view class="infoLi">
								<view class="infoLable">动力</view>
								<view class="infoVal">请选择
									<uni-icons class="rightIcon" color="#3B86FF" size="18" type="forward" />
								</view>
							</view>
							<view class="infoLi">
								<view class="infoLable">外观颜色</view>
								<view class="infoVal">请选择
									<uni-icons class="rightIcon" color="#3B86FF" size="18" type="forward" />
								</view>
							</view>
							<view class="infoLi">
								<view class="infoLable">内饰颜色</view>
								<view class="infoVal">请选择
									<uni-icons class="rightIcon" color="#3B86FF" size="18" type="forward" />
								</view>
							</view>
						</view> -->
					</block>
					<view class="infoLi">
						<view class="infoLable">竞争对手</view>
						<view class="infoVal">
							<input v-model="formObj.competitor" class="inputStyle" placeholder="请输入" placeholder-style="color: rgba(67,66,93, 0.5)" />
						</view>
					</view>
					<view class="infoLi">
						<view class="infoLable">竞争车型</view>
						<view class="infoVal">
							<input v-model="formObj.compModel" class="inputStyle" placeholder="请输入" placeholder-style="color: rgba(67,66,93, 0.5)" />
						</view>
					</view>
					<view class="infoLi supplyInfo">
						<view class="infoLable">其他补充信息</view>
						<textarea v-model="formObj.remark" class="textareaInfo" placeholder-style="color: rgba(67,66,93, 0.5)" placeholder="请输入信息" maxlength="200"></textarea>
						<view class="limit">{{ formObj.remark && formObj.remark.length > 0 ? formObj.remark.length : 0}}/200</view>
					</view>
				</view>
			</view>

			<view class="operateBox">
				<view class="operateBtn cancelBtn" @click="cancelForm()">取消</view>
				<view class="operateBtn" @click="subForm('planning')">保存</view>
				<view class="operateBtn" @click="subForm('completed')">跟进完成</view>
				
			</view>
		</view>
		
		<tki-tree ref="tkitree" :selectParent="false" :multiple="true" :range="reasonList" :selectQuantity="3" :foldAll="false" idKey="code" rangeKey="message" @confirm="treeConfirm" @cancel="treeCancel"></tki-tree>
	</view>
</template>

<script>
	import {
		addClueFollow,
		getClueRuleOem,
		getCommonEnums,
		getAppActivities,
		getFollowDetail
	} from '@/service/api/api.js';
	import {
		parseTime
	} from "@/common/util.js"
	import uniIcons from "@/components/uni-icons/uni-icons.vue";
	import channelPicker from '../components/channelPicker.vue';
	import tkiTree from '@/components/tki-tree/tki-tree.vue';
	export default {
		components: {
			uniIcons,
			channelPicker,
			tkiTree
		},
		data() {
			return {
				userInfo: {},
				id: '',
				currentFollowNum: '0', //当前跟进次数
				followNum: '', //跟进次数配置
				clueStatus: '',	//线索状态
				exhibition: '5', //1无效线索、2战败、3到店邀约、4退单、5非单一目的 
				isEdit: false, //是否为编辑
				isInfoLiLeveItem:null,//意向级别选中
				isRadioVal:true, 
				list: [
						{
							name: '是',
							disabled: false
						},
						{
							name: '否',
							disabled: false
						},
					],
				followUpFormArr: [{
					followUpVal: 'phone',
					fallowUpName: '打电话',
					isChecked: false,
				}, {
					followUpVal: 'sms',
					fallowUpName: '发信息',
					isChecked: false,
				}, {
					followUpVal: 'come_shop',
					fallowUpName: '来店面谈',
					isChecked: false,
				}, {
					followUpVal: 'outside_shop',
					fallowUpName: '店外会面',
					isChecked: false,
				}],
				objective_radio_Arr: [{
					objectiveVal: '1',
					objectiveName: '无效线索',
					isChecked: false
				}, {
					objectiveVal: '2',
					objectiveName: '战败',
					isChecked: false
				}, {
					objectiveVal: '3',
					objectiveName: '到店邀约',
					isChecked: false
				}, {
					objectiveVal: '14',
					objectiveName: '退单',
					isChecked: false
				}],
				objective_checkbox_Arr: [{
					objectiveVal: '4',
					objectiveName: '到店面谈',
					isChecked: false
				}, {
					objectiveVal: '5',
					objectiveName: '试驾邀约',
					isChecked: false
				}, {
					objectiveVal: '6',
					objectiveName: '试驾体验',
					isChecked: false
				}, {
					objectiveVal: '7',
					objectiveName: '活动邀约',
					isChecked: false
				}, {
					objectiveVal: '8',
					objectiveName: '参加活动',
					isChecked: false
				}, {
					objectiveVal: '9',
					objectiveName: '价格谈判',
					isChecked: false
				},{
					objectiveVal: '10',
					objectiveName: '下订',
					isChecked: false
				}, {
					objectiveVal: '11',
					objectiveName: '成交',
					isChecked: false
				},  {
					objectiveVal: '12',
					objectiveName: '交车',
					isChecked: false
				},{
					objectiveVal: '13',
					objectiveName: '成交回访',
					isChecked: false
				}, {
					objectiveVal: '15',
					objectiveName: '保持联系',
					isChecked: false
				}, ],
				levelArr : ['O', 'H', 'A', 'B', 'C'],
				formObj: {
					deptId: '',
					userId: '',
					uniqueId: '',
					followUp: '',
					followPurposes: [],
					followTime: '',
					intentionLevel: '',
					invalidReasons: [],
					invalidReasonsStr: [],
					followStatus: '',
					competitor: '',
					compModel: '',
					remark: '',
					// startTime: '',
					// endTime: '',
					intentCarBrand: '',
					intentCarModel: '',
					intentCarStyle: '',
					activityId: '',
					activityName: '',
					firstChannelId: '',
					secondChannelId: '',
					channelName: '',
					estTranTime: '',
					config: '',
					power: '',
					exteriorColor: '',
					interiorColor: '',
					promiseShop: false,
				},
				reasonList: [],
				activityArr: [],
				actIndex: 0,
				
			}
		},
		computed:{
			intentionCar(){
				return this.$store.state.intentionCar
			}
		},
		watch:{
			intentionCar (newVal, oldVal) {
				// 数据变化后，调用b组件内的函数
				// console.log(newVal)
				this.formObj.intentCarBrand = newVal.intentCarBrand,
				this.formObj.intentCarModel = newVal.intentCarModel,
				this.formObj.intentCarStyle = newVal.intentCarStyle
			}
		},
		filters: {
			dataFormat(val) {
				return parseTime(val, '{y}-{m}-{d} {h}:{i}')
			}
		},
		onLoad(option) {
			// id 跟进id, uniqueId 唯一id, followUp 形式, followNum 跟进次数,followPurposes 目的
			
			option.followUp = option.followUp ? option.followUp : 'come_shop'
			try {
				this.userInfo = uni.getStorageSync('user_info')
				this.followUpFormArr = this.followUpFormArr.map((item, idx) => {
					item.isChecked = item.followUpVal == option.followUp ? true : false
					return item
				})
				// console.log(option,"optionoptionoption")
				this.formObj.uniqueId = option.uniqueId || ''
				this.newcluePhone=option.phone || ''
				this.formObj.followUp = option.followUp
				this.currentFollowNum = option.followNum || 0
				this.formObj.followPurposes = option.followPurposes ? option.followPurposes.split(',') : [],
				this.clueStatus = option.clueStatus || ''
				
				if (this.clueStatus == '已下订' || this.clueStatus == '已成交' || this.clueStatus == '已交车') {
					this.formObj.followUp = 'come_shop'
					this.followUpClick('2')
					this.objectiveRadioClick('3', this.objective_radio_Arr['3'])
				}
				
				this.isEdit = option.id ? true : false
				this.id = option.id
			} catch (e) {

			}

			this.init()
		},
		onUnload() {
			this.$store.commit('changeIntentionCar', {})
		},
		created() {
			// console.log(this.$route,"this.$routethis.$route")
		},
		methods: {
			init() {
				this.getRuleOem()
				this.getEnums()
				this.getActivities()
				
				if(this.isEdit) {	//为编辑
					this.getDetails()
				}
			},
			
			getDetails() {
				getFollowDetail({
					id: this.id
				}).then(res => {
					if (res.data.code == 0) {
						let resData = res.data.data
						if(resData){
							delete resData.createTime
							delete resData.updateTime
							delete resData.salesManageId
							delete resData.salesmanId
							// delete resData.ownerDeptId
							// delete resData.owner
							this.levelArr.forEach((v,i)=>{
								if(v==resData.intentionLevel){
									this.isInfoLiLeveItem=i
								}
							})
							resData.followTime = resData.followTime ? parseTime(resData.followTime, '{y}-{m}-{d}') : ''
							resData.startTime = resData.startTime ? parseTime(resData.startTime, '{y}-{m}-{d}') : ''
							resData.endTime = resData.endTime ? parseTime(resData.endTime, '{y}-{m}-{d}') : ''
							resData.estTranTime = resData.estTranTime ? parseTime(resData.estTranTime, '{y}-{m}-{d}') : ''							
							this.objective_radio_Arr.forEach(x => {
								if(resData.followPurposes.indexOf(x.objectiveVal) != -1) {
									x.isChecked = true
								}
							})
							this.objective_checkbox_Arr.forEach(x => {
								if(resData.followPurposes.indexOf(x.objectiveVal) != -1) {
									x.isChecked = true
								}
							})
							
							this.activityArr.forEach((x,idx) => {
								if(x.activityId == resData.activityId){
									this.actIndex = idx
									resData.activityName = x.activityName
								}
							})
							
							if(resData.firstChannelName && resData.secondChannelName) {
								resData.channelName = resData.firstChannelName +'/'+ resData.secondChannelName
							}	
							
							let followPurposes = resData.followPurposes
							if(followPurposes && followPurposes.indexOf('1') != -1){
								this.exhibition = '1'
							} else if(followPurposes && followPurposes.indexOf('2') != -1){
								this.exhibition = '2'
							} else if(followPurposes && followPurposes.indexOf('3') != -1){
								this.exhibition = '3'
							} else if(followPurposes && followPurposes.indexOf('4') != -1){
								this.exhibition = '4'
							} else {
								this.exhibition = '5'
							}

						}
						// console.log(resData)
						this.formObj = resData || {}
					}
				})
			},
			
			isChannel(type){
				let flag = true
				if(type == '0') {	//活动名称
					return this.formObj.followPurposes ? this.formObj.followPurposes.indexOf('7') != -1 || this.formObj.followPurposes.indexOf('8') != -1 : false
				}else if(type == '1'){	// 来源渠道
					return this.formObj.followPurposes ? this.formObj.followPurposes.indexOf('3') != -1 || this.formObj.followPurposes.indexOf('8') != -1 : false
				} else if (type == '2') {	//到店承诺
					return this.formObj.followPurposes ? this.formObj.followPurposes.indexOf('3') != -1 || this.formObj.followPurposes.indexOf('5') != -1 || this.formObj.followPurposes.indexOf('7') != -1 : false
				}
			},
			
			getRuleOem() {
				getClueRuleOem({
					deptId: this.userInfo.userDeptId
				}).then(res => {
					if (res.data.code == 0) {
						this.followNum = res.data.data.followNum || 0
					}
				})
			},
			
			getEnums() {
				getCommonEnums({
					type: 'InvalidReason'
				}).then(res => {
					if (res.data.code == 0) {
						this.reasonList = res.data.data || []
					}
				})
			},
			
			getActivities() {
				getAppActivities({}).then(res => {
					if (res.data.code == 0) {
						this.activityArr = res.data.data.map(item => {
							return {
								activityId: item.activityId,
								activityName: item.activityName,
								firstChannelId: item.firstChannelId,
								secondChannelId: item.secondChannelId
							}
						}) || []
					}
				})
			},

			upInfo(isAll) {
				this.objective_radio_Arr = this.objective_radio_Arr.map((item, idx) => {
					item.isChecked = false
					return item
				})
				this.objective_checkbox_Arr = this.objective_checkbox_Arr.map(item => {
					item.isChecked = false
					return item
				})
				this.formObj = {
					...this.formObj,
					followTime: '',
					intentionLevel: '',
					invalidReasons: [],
					invalidReasonsStr: [],
					followStatus: '',
					competitor: '',
					compModel: '',
					remark: '',
					startTime: '',
					endTime: '',
					intentCarBrand: '',
					intentCarModel: '',
					intentCarStyle: '',
					activityId: '',
					activityName: '',
					firstChannelId: '',
					secondChannelId: '',
					channelName: '',
					estTranTime: '',
					config: '',
					power: '',
					exteriorColor: '',
					interiorColor: '',
					promiseShop: false,
				}
				
				if(isAll) {
					this.formObj.followPurposes = []
				}
				this.$forceUpdate()
			},

			followUpClick(index) {
				this.upInfo(true)
				this.isInfoLiLeveItem=null
				this.formObj.intentionLevel=''

				this.followUpFormArr = this.followUpFormArr.map((item, idx) => {
					if (index == idx) {
						item.isChecked = true
						this.formObj.followUp = item.followUpVal
					} else {
						item.isChecked = false
					}
					return item
				})
				// console.log(this.formObj.followUp)
				
			},

			objectiveRadioClick(index, val) {
				let exhibition = this.exhibition
				this.upInfo()
				let flag = this.switchObjective(val.objectiveVal)
				if (flag == '1') {
					this.exhibition = exhibition
					return false
				}

				this.objective_radio_Arr = this.objective_radio_Arr.map((item, idx) => {
					
					// this.formObj.followPurposes = []
					
					if (index == idx && !item.isChecked) {
						item.isChecked = true
						this.formObj.followPurposes = [item.objectiveVal]
					} else if(index == idx && item.isChecked) {
						item.isChecked = false
						this.formObj.followPurposes = []
					} else {
						item.isChecked = false
					}
					return item
				})
				
				this.objective_checkbox_Arr = this.objective_checkbox_Arr.map(item => {
					item.isChecked = false
					return item
				})
				// console.log(this.formObj.followPurposes)
			},

			objectiveCheckboxClick(index, val) {
				// console.log(index, val,val.objectiveVal,"index, valindex, valindex, val")
				
				let exhibition = this.exhibition
				let flag = this.switchObjective(val.objectiveVal)
				if (flag == '1') {
					this.exhibition = exhibition
					return false
				}

				let followPurposes = this.formObj.followPurposes || []
				this.objective_radio_Arr = this.objective_radio_Arr.map((item, idx) => {
					// console.log(item.isChecked,"item.isChecked")
					if (item.isChecked) {
						let i = followPurposes.indexOf(item.objectiveVal)

						if (i != -1) {
							followPurposes.splice(i, 1);
						}
						item.isChecked = false
					}
					return item
				})

				if (this.objective_checkbox_Arr[index].isChecked) {
					let i = followPurposes.indexOf(this.objective_checkbox_Arr[index].objectiveVal)

					if (i != -1) {
						followPurposes.splice(i, 1);
					}
					this.objective_checkbox_Arr[index].isChecked = false
				} else {
					if (followPurposes && followPurposes.length >= 3) {
						uni.showToast({
							icon: "none",
							title: "最多选择三个哦"
						})
						return false
					}
					this.objective_checkbox_Arr[index].isChecked = true
					followPurposes.push(this.objective_checkbox_Arr[index].objectiveVal)
				}

				// console.log(followPurposes)
				this.formObj.followPurposes = followPurposes
			},

			switchObjective(n) {
				let flag = 0
				this.exhibition = '5'
				switch (n) {
					case '1':
						//无效线索
						console.log(this.currentFollowNum,this.followNum,'this.currentFollowNum,this.followNum')
						if (this.currentFollowNum >= this.followNum) {
							uni.showToast({
								icon: "none",
								title: `跟进次数大于${this.followNum}，不可以选择哦`
							})
							flag = 1
						} 
							this.exhibition = '1'
						break;
					case '2':
						// 战败
						console.log(this.currentFollowNum,this.followNum)
						if (this.currentFollowNum < this.followNum) {
							uni.showToast({
								icon: "none",
								title: `跟进次数小于等于${this.followNum}，不可以选择哦`
							})
							flag = 1
						} 
							this.exhibition = '2'
						

						break;
					case '3':
						// 到店邀约（客户承诺参与必填）
						if (this.formObj.followUp != 'phone' && this.formObj.followUp != 'sms' ) { //不等于电话和信息
							uni.showToast({
								icon: "none",
								title: `只有电话和信息可以选择哦`
							})
							flag = 1
						} 
						this.exhibition = '3'
												
						break;
					case '14':
						// 退单(线索状态：已下订、已成交、已交车；退单原因必填)
						if (this.formObj.followUp != 'come_shop' && (this.clueStatus != '已下订' || this.clueStatus != '已成交' || this.clueStatus != '已交车')) { //不等于来店面谈
							uni.showToast({
								icon: "none",
								title: `只有来店面谈可以选择哦`
							})
							flag = 1
						} 
						this.exhibition = '4'
						
						break;
					case '4':
						// 到店面谈
						if (this.formObj.followUp != 'come_shop') { //不等于来店面谈
							uni.showToast({
								icon: "none",
								title: `只有来店面谈可以选择哦`
							})
							flag = 1
						}
						break;
					case '5':
						// 试驾邀约（客户承诺参与必填）
						break;
					case '6':
						// 试驾体验
						if (this.formObj.followUp != 'come_shop') { //不等于来店面谈
							uni.showToast({
								icon: "none",
								title: `只有来店面谈可以选择哦`
							})
							flag = 1
						}
						break;
					case '7':
						// 活动邀约（营销活动，客户承诺参与必填）
						break;
					case '8':
						// 参加活动（营销活动，来源渠道必填）
						if (this.formObj.followUp != 'come_shop') { //不等于来店面谈
							uni.showToast({
								icon: "none",
								title: `只有来店面谈可以选择哦`
							})
							flag = 1
						}
						break;
					case '9':
						// 价格谈判
						break;
					case '11':
						// 成交
						if (this.formObj.followUp != 'come_shop' && this.formObj.followUp != 'phone') { //不等于来店面谈
							uni.showToast({
								icon: "none",
								title: `只有来店面谈且电话沟通时可以选择哦`
							})
							flag = 1
						}
						break;
					case '13':
						// 成交回访（线索状态：已交车）
						if ((this.formObj.followUp != 'phone' && this.formObj.followUp != 'sms') || this.clueStatus != '已交车' ) {
							uni.showToast({
								icon: "none",
								title: `只有电话沟通和信息跟进且已交车时可以选择哦`
							})
							flag = 1
						}
						break;
					case '15':
						// 保持联系（线索状态：已交车）
						console.log(this.clueStatus , this.formObj.followUp)
						// console.log(this.formObj.followUp == "phone",'---followUp保持联系1')
						// console.log(this.clueStatus == "已交车",'---clueStatus保持联系2')
						// if ((this.formObj.followUp != 'phone' || this.formObj.followUp != 'sms') && this.clueStatus != '已交车') {
						// if (this.clueStatus != '已交车' && this.formObj.followUp != 'phone' ) {
						// 	uni.showToast({
						// 		icon: "none",
						// 		title: `只有电话沟通且已交车时可以选择哦`
						// 	})
						// 	flag = 1
						// }			
						if (this.clueStatus == '已交车' && this.formObj.followUp == 'phone' ) {
							flag = 0
						}else{
							uni.showToast({
								icon: "none",
								title: `只有电话沟通且已交车时可以选择哦`
							})
							flag = 1
						}
						break;
					case '10':
						// 下订
						if (this.formObj.followUp != 'come_shop' && this.formObj.followUp != 'phone') {
							uni.showToast({
								icon: "none",
								title: `只有来店面谈或电话沟通时可以选择哦`
							})
							flag = 1
						}
						break;
					case '12':
						// 交车
						if (this.formObj.followUp != 'come_shop') { //不等于来店面谈
							uni.showToast({
								icon: "none",
								title: `只有来店面谈可以选择哦`
							})
							flag = 1
						}
						break;
						// default:
				}

				return flag;
			},
			isboob(res1,res2){

			},
			bindDateChange(e, type) {
				if (type == '0') {
					this.formObj.startTime = e.detail.value
				} else if (type == '1') {
					this.formObj.endTime = e.detail.value
				} else if (type == '2') {
					this.formObj.followTime = e.detail.value
				} else if (type == '3') {
					this.formObj.estTranTime = e.detail.value
				}
			},

			//意向等级选中
			leveitemCheFun(leveitem,leveidx){
				this.isInfoLiLeveItem=leveidx
				if(this.isInfoLiLeveItem!=null){
					this.formObj.intentionLevel=leveitem
				}		
					console.log(this.formObj.intentionLevel)
			},
			
			isCheckedFun(){
			  this.isRadioVal=!this.isRadioVal
			  this.formObj.promiseShop=this.isRadioVal
			},

			getIntentionCar() {
				uni.navigateTo({
					url: '/pages/clue/series/index'
				})
			},
			
			activityChange(e) {
				let index = e.target.value
				this.actIndex = index
				// console.log(index)
				let activityObj = this.activityArr[index]
				
				this.formObj.activityId = activityObj.activityId
				this.formObj.activityName = activityObj.activityName
				this.formObj.firstChannelId = activityObj.firstChannelId
				this.formObj.secondChannelId = activityObj.secondChannelId
			},
			
			handleGetRegion(region) {
				this.formObj.firstChannelId = region[0].channelId
				this.formObj.secondChannelId = region[1].channelId
				
				this.formObj.channelName = region[0].name +'/'+ region[1].name
			},
			
			// 显示树形选择器
			showTree() {
				this.$refs.tkitree._show();
			},
			
			// 确定回调事件
			treeConfirm(e) {
				let invalidReasonsStr = []
				let  invalidReasons = []
				// console.log(e)
				if(e && e.length > 0) {
					invalidReasonsStr = e.map((item,idx) => {
						return item.message;
					})	
					invalidReasons = e.map((item,idx) => {
						return item.code;
					})
				}
				// console.log(invalidReasonsStr,invalidReasonsCodes,"invalidReasonsCodeinvalidReasonsCodeinvalidReasonsCodeinvalidReasonsCode")
				this.formObj.invalidReasonsStr = invalidReasonsStr 
				this.formObj.invalidReasons= invalidReasons
			},
			joinStr(val) {
				return val ? val.join() : ''
			},
			treeCancel(e) {
				
			},
			cancelForm() {
				if(this.isEdit) {
					uni.showModal({
					    title: '提示',
					    content: '是否要取消该次跟进',
					    success:  (res)=> {
					        if (res.confirm) {
					            // 不更新该次跟进，再次弹出新的新建跟进页面
						
								uni.redirectTo({
									// id 跟进id, uniqueId 唯一id, followUp 形式, followNum 跟进次数,followPurposes 目的 clueStatus 线索状态
									url: `/pages/clue/clueFollowUp/index?uniqueId=${this.formObj.uniqueId}&followNum=${this.currentFollowNum || 0}&followPurposes=${this.formObj.followPurposes.join()}&followUp=${this.formObj.followUp}&clueStatus=${this.clueStatus}`
								})
					        } else if (res.cancel) {
					           this.goBack()
						
					        }
					    }
					});
				} else {
					 this.goBack()
			
				}
			},
				
			subForm(followStatus) { //提交表单

				let data = {
					...this.formObj,
					followStatus,
					deptId: this.userInfo.userDeptId,
					userId: this.userInfo.userId,
				}	
				try {
					if (!data.followTime) {
						throw new Error('请选择跟进时间')
					} else {
						data.followTime = data.followTime ? data.followTime.replace(/-/g,  "/") : ''
					}
					// console.log(data.followTime)
					if (!data.intentionLevel) {
						throw new Error('请选择意向级别')
					}

					if (this.exhibition == '3' || this.exhibition == '5') {
						if (!data.intentCarStyle) {
							throw new Error('请选择意向车型')
						}
					}

					if (this.exhibition == '1' || this.exhibition == '2') {
						if (!data.invalidReasons || data.invalidReasons.length <= 0) {
							throw new Error(this.exhibition == '1' ? '请选择战败原因' : '请选择退单原因')
						}
					}

					if (this.exhibition == '3') {
						if ((!data.firstChannelId || !data.secondChannelId) && (data.followPurposes.indexOf('7') != -1 || data.followPurposes.indexOf('8') != -1)) {
							throw new Error('请选择来源渠道')
						}
						
						// if ((data.promiseShop=="" || data.promiseShop==null || data.promiseShop==undefined) && (data.followPurposes.indexOf('3') != -1 || data.followPurposes.indexOf('5') != -1 || data.followPurposes.indexOf('7') != -1)) {
						// 	throw new Error('请选择客户承诺到店')
						// }
					}

					if (this.exhibition == '5') {
						if (!data.activityId && (data.followPurposes.indexOf('7') != -1 || data.followPurposes.indexOf('8') != -1)) {
							throw new Error('请选择活动')
						}
					}
					
					// if(this.isEdit) {
					// 	if (!data.startTime) {
					// 		throw new Error('请选择开始时间')
					// 	} else {
					// 		data.startTime = data.startTime ? data.startTime.replace(/-/g,  "/") : ''
					// 	}
						
					// 	if (!data.endTime) {
					// 		throw new Error('请选择结束时间')
					// 	} else {
					// 		data.endTime = data.endTime ? data.endTime.replace(/-/g,  "/") : ''
					// 	}
					// } else {
						delete data.startTime
						delete data.endTime
					// 	// delete data.uniqueId
					// }
				} catch (e) {
					uni.showToast({
						title: e.message,
						icon: 'none',
					})

					return false
				}

				data.followPurposes =  data.followPurposes ? data.followPurposes.join() : ''
				data.estTranTime = data.estTranTime ? data.estTranTime.replace(/-/g,  "/") : ''
				
				if(!data.estTranTime) {
					delete data.estTranTime
				}
				
				if(!data.followTime) {
					delete data.followTime
				}
				
				if(!data.estTranTime) {
					delete data.estTranTime
				}
				
				delete data.invalidReasonsStr
				
				console.log(data,"data提交数据")
				
				this.addFollow(data)
			},
			
			addFollow(data) {
				
				addClueFollow(data).then(res => {
					if (res.data.code == '0') {
						uni.showToast({
							title: '保存成功',
							icon: 'success'
						})
						// uni.redirectTo({
						// 	url: `/pages/clue/clueDetails/index?id=${res.data.data.id}&uniqueId=${res.data.data.uniqueId}&phone=${res.data.data.mobile || this.newcluePhone}&followNum=${res.data.data.invalidNum || 0}&tabIdx=0&clueStatus=${res.data.data.clueStatus}`
						// })
						this.goBack()
					} else {
						uni.showToast({
							title: res.data.errMsg,
							icon: 'none',
						})
					}
				})
			},

			goBack() { //返回上一层
				uni.navigateBack()
			}
		}
	}
</script>

<style scoped lang="scss">
	@import './index.scss'
</style>
